<!-- 运单费用 -->
<template>
  <div class="goods-sum-box">
    <div>
      总体积<span class="value-color">
        {{ formatNumber(summaries.totalVolume)}}方</span>
    </div>，
    <div>
      总重量<span class="value-color">
        {{ formatNumber(summaries.totalWeight) }}公斤</span>
    </div>，
    <div>
      总数量<span class="value-color">
        {{ formatNumber(summaries.totalQuantity) }}件</span>
    </div>，
    <div>
      总费用<span class="value-color">
        {{ formatNumber(summaries.totalFee)  }}元</span>
    </div>
  </div>
</template>

<script>
import { transport } from '@/api'
export default {
  name: "CombineSummaries",
  props: {
    filter: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      summaries: {}
    }
  },
  computed: {
    formatNumber () {
      return num => num ? Number(num).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') : 0;
    }
  },
  watch: {
    filter: {
      deep: true,
      immediate: true,
      handler (value) {
        if (value?.page) {
          this.loadSummaries();
        }
      }
    }
  },
  methods: {
    async loadSummaries () {
      // for (let ele in this.filter) {
      //   if (this.filter[ele] && ele.includes("Time") || ele.includes("Date")) {
      //     this.filter[`${ele}Begin`] = this.$moment(this.filter[ele][0]).format("YYYY-MM-DD") + " 00:00:00";
      //     this.filter[`${ele}End`] = this.$moment(this.filter[ele][1]).format("YYYY-MM-DD") + " 23:59:59";
      //   }
      // }
      const response = await transport.combineSum(this.filter);
      if (0 !== response?.code) {
        console.log("获取合单统计数据失败", response)
        return
      }
      this.summaries = response.data;
    }
  }
};
</script>

<style scoped>
.goods-sum-box {
  display: flex;
  padding-top: 20px;
  line-height: 30px;
  color: var(--prev-color-text-ashes);
  padding-right: 80px;
}
.value-color {
  color: var(--prev-color-primary) !important;
}
</style>
